package com.huifaapp.mall.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.DetailsofPaymentActivity;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.base.bean.PayBean;
import com.huifaapp.mall.bean.DetailsBalance;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.Contig;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * Created by Administrator on 2018/1/9.
 */

public class TakePhotoPopWin extends PopupWindow implements View.OnClickListener {

//    private Button btnTakePhoto, btnSelect, btnCancel;
    private View mPopView;
    private OnItemClickListener mListener;
    private LinearLayout ll_wx_pay,ll_zfb_pay,ll_fq_pay,ll_ye_pay,ll_ye_pay_no;
    private TextView tv_true_pay,tv_pay_pop_yue,tv_pay_pop_yue_no;
    private ImageView iv_ye_pay,iv_wx_pay,iv_zfb_pay,iv_fq_pay,iv_fq_pay_no,iv_pay_close;

    public TakePhotoPopWin(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        init(context);
        setPopupWindow();
//        btnTakePhoto.setOnClickListener(this);
//        btnSelect.setOnClickListener(this);
//        btnCancel.setOnClickListener(this);
        ll_wx_pay.setOnClickListener(this);
        ll_zfb_pay.setOnClickListener(this);
        ll_fq_pay.setOnClickListener(this);
        tv_true_pay.setOnClickListener(this);
        ll_ye_pay.setOnClickListener(this);
        ll_ye_pay_no.setOnClickListener(this);
        iv_pay_close.setOnClickListener(this);
//        if(Contig.yue==1){//余额不足
//            ll_ye_pay_no.setVisibility(View.VISIBLE);
//            ll_ye_pay.setVisibility(View.GONE);
//        }else if(Contig.yue==2){
//            ll_ye_pay_no.setVisibility(View.GONE);
//            ll_ye_pay.setVisibility(View.VISIBLE);
//        }
//        tv_pay_pop_yue.setText("余额支付(¥"+Contig.balance+")");
//        tv_pay_pop_yue_no.setText("余额支付(¥"+Contig.balance+")");
//        if(Contig.yue==1){//余额不足
//            ll_ye_pay_no.setVisibility(View.VISIBLE);
//            ll_ye_pay.setVisibility(View.GONE);
//        }else if(Contig.yue==2){
//            ll_ye_pay_no.setVisibility(View.GONE);
//            ll_ye_pay.setVisibility(View.VISIBLE);
//        }
    }

    /**
     * 初始化
     *
     * @param context
     */
    private void init(Context context) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(context);
        //绑定布局
        mPopView = inflater.inflate(R.layout.take_photo_pop, null);

//        btnTakePhoto = (Button) mPopView.findViewById(R.id.id_btn_take_photo);
//        btnSelect = (Button) mPopView.findViewById(R.id.id_btn_select);
//        btnCancel = (Button) mPopView.findViewById(R.id.id_btn_cancelo);
        ll_wx_pay= (LinearLayout) mPopView.findViewById(R.id.ll_wx_pay);
        ll_zfb_pay= (LinearLayout) mPopView.findViewById(R.id.ll_zfb_pay);
        ll_fq_pay= (LinearLayout) mPopView.findViewById(R.id.ll_fq_pay);
        ll_ye_pay= (LinearLayout) mPopView.findViewById(R.id.ll_ye_pay);
        ll_ye_pay_no= (LinearLayout) mPopView.findViewById(R.id.ll_ye_pay_no);
        tv_true_pay= (TextView) mPopView.findViewById(R.id.tv_true_pay);
        tv_pay_pop_yue= (TextView) mPopView.findViewById(R.id.tv_pay_pop_yue);
        tv_pay_pop_yue_no= (TextView) mPopView.findViewById(R.id.tv_pay_pop_yue_no);
        iv_ye_pay= (ImageView) mPopView.findViewById(R.id.iv_ye_pay);
        iv_wx_pay= (ImageView) mPopView.findViewById(R.id.iv_wx_pay);
        iv_zfb_pay= (ImageView) mPopView.findViewById(R.id.iv_zfb_pay);
        iv_fq_pay= (ImageView) mPopView.findViewById(R.id.iv_fq_pay);
        iv_fq_pay_no= (ImageView) mPopView.findViewById(R.id.iv_fq_pay_no);
        iv_pay_close= (ImageView) mPopView.findViewById(R.id.iv_pay_close);
        iv_ye_pay.setVisibility(View.GONE);
        iv_wx_pay.setVisibility(View.VISIBLE);
        iv_zfb_pay.setVisibility(View.GONE);
        iv_fq_pay.setVisibility(View.GONE);
        iv_fq_pay_no.setVisibility(View.GONE);


    }

    /**
     * 设置窗口的相关属性
     */
    @SuppressLint("InlinedApi")
    private void setPopupWindow() {
        this.setContentView(mPopView);// 设置View
        this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的宽
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);// 设置弹出窗口的高
        this.setFocusable(true);// 设置弹出窗口可
        this.setAnimationStyle(R.style.take_photo_anim);// 设置动画
        this.setBackgroundDrawable(new ColorDrawable(0x00000000));// 设置背景透明
        mPopView.setOnTouchListener(new View.OnTouchListener() {// 如果触摸位置在窗口外面则销毁

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int height = mPopView.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }

    /**
     * 定义一个接口，公布出去 在Activity中操作按钮的单击事件
     */
    public interface OnItemClickListener {
        void setOnItemClick(View v);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (mListener != null) {
            mListener.setOnItemClick(v);
        }
        switch (v.getId()){
            case R.id.ll_ye_pay:
                iv_ye_pay.setVisibility(View.VISIBLE);
                iv_wx_pay.setVisibility(View.GONE);
                iv_zfb_pay.setVisibility(View.GONE);
                iv_fq_pay.setVisibility(View.GONE);
                iv_fq_pay_no.setVisibility(View.GONE);
                break;
            case R.id.ll_wx_pay:
                iv_ye_pay.setVisibility(View.GONE);
                iv_wx_pay.setVisibility(View.VISIBLE);
                iv_zfb_pay.setVisibility(View.GONE);
                iv_fq_pay.setVisibility(View.GONE);
                iv_fq_pay_no.setVisibility(View.GONE);
                break;
            case R.id.ll_zfb_pay:
                iv_ye_pay.setVisibility(View.GONE);
                iv_wx_pay.setVisibility(View.GONE);
                iv_zfb_pay.setVisibility(View.VISIBLE);
                iv_fq_pay.setVisibility(View.GONE);
                iv_fq_pay_no.setVisibility(View.GONE);
                break;
            case R.id.ll_fq_pay:
                iv_ye_pay.setVisibility(View.GONE);
                iv_wx_pay.setVisibility(View.GONE);
                iv_zfb_pay.setVisibility(View.GONE);
                iv_fq_pay.setVisibility(View.VISIBLE);
                iv_fq_pay_no.setVisibility(View.GONE);
                break;
            case R.id.ll_ye_pay_no:
                iv_ye_pay.setVisibility(View.GONE);
                iv_wx_pay.setVisibility(View.GONE);
                iv_zfb_pay.setVisibility(View.GONE);
                iv_fq_pay.setVisibility(View.GONE);
                iv_fq_pay_no.setVisibility(View.VISIBLE);
                break;

        }
    }

}

